package com.darcey.gfx
{
	// -------------------------------------------------------------------------------------------------------------------------------
	import com.darcey.debug.Ttrace;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;

	// -------------------------------------------------------------------------------------------------------------------------------
	
	
	
	// -------------------------------------------------------------------------------------------------------------------------------
	public class GetBitmap
	{
		// ---------------------------------------------------------------------------------------------------------------------------
		private var t:Ttrace;
		private static var bmp:Bitmap;
		private static var bmpData:BitmapData;
		// ---------------------------------------------------------------------------------------------------------------------------
		
		
		
		// ---------------------------------------------------------------------------------------------------------------------------
		public function GetBitmap()
		{
		}
		// ---------------------------------------------------------------------------------------------------------------------------
		
		
		// ---------------------------------------------------------------------------------------------------------------------------
		public static function of(target:DisplayObject,w:Number = 0, h:Number = 0):Bitmap
		{
			if (w==0 || h == 0){
				bmpData = new BitmapData( target.width, target.height );
			} else {
				bmpData = new BitmapData( w, h );
			}
			
			bmpData.draw(target);
			bmp = new Bitmap(bmpData);
			return bmp;
		}
		// ---------------------------------------------------------------------------------------------------------------------------
		
		
		
		// ---------------------------------------------------------------------------------------------------------------------------
		public static function getBitmapData():BitmapData
		{
			if (bmp != null){
				return bmpData;
			} else {
				trace("GetBitmap().getBitmapData(): RETURNED NULL AS BITMAP DATA IS NULL! Use GetBitmap.of(displayobject) first!");
				return null;
			}
		}
		// ---------------------------------------------------------------------------------------------------------------------------
		
		
		
		
		
	}
	// -------------------------------------------------------------------------------------------------------------------------------
}